package com.example.travelservlet.collectionEntertainment.controller;

import com.example.travelservlet.collectionEntertainment.service.CollectionEntertainmentService;
import com.example.travelservlet.entity.CollectionEntertainment;
import com.example.travelservlet.user.domain.Result;
import com.example.travelservlet.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author 30697
 */
@RestController
@RequestMapping("/collectionEntertainment")
public class CollectionEntertainmentController {

    @Autowired
    private CollectionEntertainmentService collectionEntertainmentService;

    /**
     *
     * @param collectionId
     * @param entertainmentId
     * @return
     */
    @GetMapping("/createCollectionEntertainment/{collectionId}/{entertainmentId}")
    public Result<CollectionEntertainment> createCollectionEntertainment(@PathVariable String collectionId,
                                                                         @PathVariable String entertainmentId) {
        CollectionEntertainment collectionEntertainment = new CollectionEntertainment();
        collectionEntertainment.setCollectionId(collectionId);
        collectionEntertainment.setEntertainmentId(entertainmentId);
        collectionEntertainment.setCollectionTime(new Date());
        CollectionEntertainment save = collectionEntertainmentService.createCollectionEntertainment(collectionEntertainment);
        return ResultUtil.success(save);
    }

    @Transactional
    @GetMapping("/deleteCollectionEntertainment/{collectionId}/{entertainmentId}")
    public void deleteCollectionEntertainment(@PathVariable String collectionId,
                                              @PathVariable String entertainmentId) {
        collectionEntertainmentService.deleteCollectionEntertainmentByCollectionIdAndEntertainmentId(collectionId,entertainmentId);
    }
}
